//
//  ViewController.m
//  ios11-1
//
//  Created by mac on 15-11-2.
//  Copyright (c) 2015年 Lee. All rights reserved.
//

#import "ViewController.h"
#import "QuartzCore/QuartzCore.h"
#import "TestViewController.h"

@interface ViewController ()

{
    UILabel * l;
}
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
    
    self.title = @"我的标题栏";
    
    
    
    self.view.backgroundColor = [UIColor brownColor];
    //UILabel * l = [[UILabel alloc] initWithFrame:CGRectMake(50, 200, 100, 44)];
    l = [UILabel new];
    l.text = @"你好，世界";
    [l sizeToFit];
    l.center = CGPointMake(self.view.frame.size.width/2.0, self.view.frame.size.height/2.0);
    l.textColor = [UIColor blackColor];
    [self.view addSubview:l];
    
    UIButton * btn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [self.view bringSubviewToFront:btn];
    btn.frame = CGRectMake(100, 100, 44, 44);
    [btn setTitle:@"按钮" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    [btn addTarget:self action:@selector(onClick2:) forControlEvents:UIControlEventTouchUpInside];
    [self.view addSubview:btn];
    
    
/*    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
    view.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:view];
    
    for (int i = 0; i<5; i++) {
        UIView *v = [[UIView alloc] initWithFrame:CGRectMake(i*20+i*50, 100 , 50,i*20 + i*50)];
        v.backgroundColor = [UIColor yellowColor];
        
        v.layer.cornerRadius = 50/2.0;
        v.clipsToBounds = YES;
        
        [self.view addSubview:v];
    }
  
    UIView *line1 = [[UIView alloc]initWithFrame:CGRectMake(20, 200, 200, 200)];
    line1.layer.borderWidth = 2;
    [self.view addSubview:line1];
    UIView * yuan = [[UIView alloc] initWithFrame:CGRectMake(100, 0, 200, 200)];
    yuan.layer.cornerRadius = 100;
    yuan.layer.borderWidth = 2;
    [line1 addSubview:yuan];

    UIView *line2 = [[UIView alloc]initWithFrame:CGRectMake(0,99, 200, 2)];
    line2.backgroundColor = [UIColor blackColor];
    [line1 addSubview:line2];
    
    UIView * line3 = [[UIView alloc]initWithFrame:CGRectMake(99, 0, 2, 200)];
    line3.backgroundColor = [UIColor blackColor];
    [line1 addSubview:line3];
    
    for (int i = 0; i<5; i++) {
        CGFloat stepper = 20;
        UIView  *view = [[UIView alloc]initWithFrame:CGRectMake(20+i*stepper, 60+i*stepper, 200-2*i*stepper, 200-2*i*stepper)];
        view.backgroundColor = [UIColor whiteColor];
        view.layer.borderWidth = 1;
        [self.view addSubview:view];
    }
*/    
}

- (void)onClick:(id)sender{
    
    UIView * line = [[UIView alloc] initWithFrame:CGRectMake(0, 200, 0, 3)];
    line.backgroundColor = [UIColor blackColor];
    [self.view addSubview:line];
    
    UIView * line2 = [[UIView alloc] initWithFrame:CGRectMake(self.view.frame.size.width/2.0, 0, 6, 0)];
    line2.backgroundColor = [UIColor blackColor];
    [self.view addSubview:line2];
    
        [UIView animateWithDuration:0.6 animations:^{//匿名函数
            line.frame = CGRectMake(0, 200, self.view.frame.size.width, 3);
        } completion:^(BOOL finish){//回调函数
            [UIView animateWithDuration:0.6 animations:^{
                line2.frame = CGRectMake(self.view.frame.size.width/2.0, 0, 3, self.view.frame.size.height);
                [UIView animateWithDuration:0.6 animations:^{
                    line.frame = CGRectMake(self.view.frame.size.width,200,0,6);
                    line2.frame = CGRectMake(self.view.frame.size.width/2.0, 0, 6, self.view.frame.size.height);
                } completion:^(BOOL finish){
                    [UIView animateWithDuration:0.6 animations:^{
                        line2.frame = CGRectMake(self.view.frame.size.width/2.0, self.view.frame.size.height, 6, 0);
                    }];
                }];
            }];
        }];
    
    
}

- (void)onClick2:(id)sender{
    TestViewController * con = [[TestViewController alloc] init];
    [self.navigationController pushViewController:con animated:YES];
}





- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    //[self.view bringSubviewToFront:l];
    [UIView animateWithDuration:2 animations:^{
        l.center = CGPointMake(self.view.frame.size.width/5,44);
    }];

}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
